package com.sddfp.system.controller;

import com.sddfp.common.pojo.*;
import com.sddfp.common.result.Result;
import com.sddfp.system.service.IUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author yellow doctor
 * @since 2025-06-23
 */
@RestController
@RequestMapping("/user")
public class UserController {
    /**
     * 用户注册
     */


    @Autowired
    IUserService userService;


    @PostMapping("/regist")
    public Result regist(@RequestBody @Valid UserRegisterDto userRegisterDto){
        userService.register(userRegisterDto);
        return Result.ok("注册成功");
    }

    @PostMapping("/login")
    public Result login(@RequestBody LoginDto loginDto){
        LoginVo loginVo = userService.login(loginDto);
        return Result.ok(loginVo);
    }


    @PostMapping("/bank/card/add")
    public Result<SignatureDto> addBankAccount(@RequestBody CardBindDto cardBindDto) {
        SignatureDto signatureDto = userService.addBankAccount(cardBindDto);
        return Result.ok(signatureDto);
    }

    @ApiOperation("根据用户id查询")
    @GetMapping("/inner/findById/{userId}")
    public Result<UserInfoVo> findById(@PathVariable("userId") Long userId) {
        UserInfoVo userInfoVo = userService.findById(userId);
        return Result.ok(userInfoVo);
    }
}
